package com.ct.controller.shipping;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ct.application.shipping.model.po.ChuanYuanShenHeSearchPO;
import com.ct.application.shipping.service.impl.ChuanYuanKuShenHeService;
import com.ct.commons.BaseController;
import com.ct.commons.annotation.HasAdmin;
import com.ct.commons.annotation.HasPermissionApi;
import com.ct.commons.annotation.LoginIgnore;
import com.ct.commons.annotation.PermissionApi;
import com.ct.commons.aspect.limiter.AccessIpLimiter;
import com.ct.shipping.orm.ChuanYuanKuShenHeDO;
import com.ct.utils.jwt.UserInfo;
import com.ct.utils.threadlocal.UserThreadLocal;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

/**
 * 船员库审核
 * @author Auto Generator
 * @since 2023-08-16
 */
@RestController
@PermissionApi(title = "船员库审核",path="/api/v1/chuanyuanshenhe",code = "cysh1000",sorted = 10)
public class ChuanYuanKuShenHeController extends BaseController {

    @Resource
    private ChuanYuanKuShenHeService chuanYuanKuShenHeService;


    /**
     * 查询船员资料列表
     */
    @PostMapping("/chuanyuanshenhe/list")
    @PermissionApi(title = "查询船员资料列表",path="/api/v1/chuanyuanshenhe/list",code = "cysh1001",sorted = 1)
    public Page<ChuanYuanKuShenHeDO> getList(@RequestBody ChuanYuanShenHeSearchPO searchPO) {
        return chuanYuanKuShenHeService.getList(searchPO);
    }

    /**
     * 根据id审核通过
     */
    @HasAdmin
    @AccessIpLimiter
    @PostMapping("/chuanyuanshenhe/tongguo/{id}")
    @PermissionApi(title = "根据id审核通过",path="/api/v1/chuanyuanshenhe/tongguo/{id}",code = "cysh1002",sorted = 2)
    public Boolean tongGuo(@PathVariable("id") Long id) {
        return chuanYuanKuShenHeService.tongGuo(id);
    }




    /* =======================↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓H5页面接口↓↓↓↓↓↓↓↓↓↓==================================== */
    /* =======================↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓H5页面接口↓↓↓↓↓↓↓↓↓↓==================================== */


    /**
     * 根据openid询审核船员资料
     */
    @GetMapping("/chuanyuanshenhe/getbyopenid")
    @PermissionApi(title = "根据openid询审核船员资料",path="/api/v1/chuanyuanshenhe/getbyopenid",code = "cysh1003",sorted = 3)
    @LoginIgnore
    @HasPermissionApi
    public ChuanYuanKuShenHeDO getChuanYuanKuById(@RequestParam("openid") String openid, @RequestParam("systemId") Long systemId) {
        if(Objects.nonNull(systemId)) {
            UserInfo userInfo = new UserInfo();
            userInfo.setSystemId(systemId);
            UserThreadLocal.set(userInfo);
        }
        return chuanYuanKuShenHeService.getByOpenid(openid);
    }


    /**
     * 船员审核保存和更新--用于H5录入
     */
    @PostMapping("/chuanyuanshenhe/saveupdate")
    @LoginIgnore
    @HasPermissionApi
    public Boolean saveUpdate(@Validated @RequestBody ChuanYuanKuShenHeDO savePO) {
        if(Objects.nonNull(savePO.getSystemId())) {
            UserInfo userInfo = new UserInfo();
            userInfo.setSystemId(savePO.getSystemId());
            UserThreadLocal.set(userInfo);
        }
        if (Objects.nonNull(savePO.getId())){
            return chuanYuanKuShenHeService.updateChuanYuanKuShenHe(savePO);
        }else {
            return chuanYuanKuShenHeService.saveChuanYuanKuShenHe(savePO);
        }
    }
}
